Skip to content

Comments

network: add DetachedSignatureAvailableCheck#771

Open
parona-source wants to merge 3 commits intopkgcore:masterfrom
parona-source:detached-signature-check
Open

network: add DetachedSignatureAvailableCheck#771
parona-source wants to merge 3 commits intopkgcore:masterfrom
parona-source:detached-signature-check

Conversation

@parona-source
Copy link
Contributor

@thesamesam was interested in this

I couldn't fully follow precedent with the network tests. The check deals with multiple network requests in one go so just a mocking of the returnvalue wasn't enough.

@parona-source parona-source force-pushed the detached-signature-check branch from 8697f61 to 694a268 Compare February 14, 2026 15:50
Copy link
Member

@thesamesam thesamesam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this. It works well for me as well.

Copy link
Member

@arthurzam arthurzam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some small changes I want, but looks really good.

I even want to run it global wise to know if it finds something

for url in f.uri:
for extension in self.detached_signature_extensions:
yield (f.filename, f"{url}{extension}")
return []
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return []

no need for this return

Copy link
Contributor Author

@parona-source parona-source Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also done this way in PyPIAttestationAvailableCheck. Should that be changed as well?

I mostly copied that check.

Copy link
Contributor Author

@parona-source parona-source Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied suggestion. Didn't touch PyPIAttestationAvailableCheck

Edit: Touched it by minimising it as well.

Comment on lines 535 to 536
result = future.result()
if result is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
result = future.result()
if result is not None:
if (result := future.result()):

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_UrlCheck and PypiAttestationAvailableCheck do this as well. Should I touch these?

Copy link
Contributor Author

@parona-source parona-source Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Realised I could minimise duplicated code by using _UrlCheck. Didn't touch them but I removed this from the new check.

PypiAttestationAvailableCheck looks like it could get minimised as well.

Edit: Touched them.

@parona-source parona-source force-pushed the detached-signature-check branch from 694a268 to 4269370 Compare February 18, 2026 11:53
Signed-off-by: Alfred Wingate <parona@protonmail.com>
@parona-source parona-source force-pushed the detached-signature-check branch from 4269370 to 9f22eac Compare February 18, 2026 11:55
Signed-off-by: Alfred Wingate <parona@protonmail.com>
Signed-off-by: Alfred Wingate <parona@protonmail.com>
@ferringb
Copy link
Contributor

The code looks fine- these are just potential points of polish or questions about being brutally paranoid about robustness ;)

I couldn't fully follow precedent with the network tests. The check deals with multiple network requests in one go so just a mocking of the returnvalue wasn't enough.

I don't know that code in question, but that sounds like something our test utilities should be enhanced to support. Mind cutting a ticket laying out what you think it should be? IE, what would've allowed you to use it rather than having to sidestep it?


result = future.result()
if result is not None:
if result := future.result():
Copy link
Contributor

@ferringb ferringb Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any scenario where result can validly be not bool(future.result()) for a returned result?

In terms of actual 'api' safety, a check of future.done() is safer, but it's also a more obnoxious chain of calls..

I mention it in reading the code; this is neither a "must" nor a "should"; just an observation since this is being converted away from is None



class PyPIAttestationAvailableCheck(NetworkCheck):
class PyPIAttestationAvailableCheck(_UrlCheck):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated to your change, but we should promote _UrlCheck to a public base, albeit after lacing ABC through it.

self._schedule_check(self._provenance_check, filename, url, executor, futures, pkg=pkg)


class DetachedSignatureAvailable(results.VersionResult, results.Info):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI- none of this inheritance chain currently sets __slots__, but they'll be converted over. That's both to prevent accidental access, and for serialization speed reasons..

No change needed here, again, just FYI.


def _verifysig_check(self, filename, url, *, pkg):
"""Check for typical verify sig URLS."""
result = None
Copy link
Contributor

@ferringb ferringb Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on converting this flow to just be returns? Your code is fine- there's no possible uninitialized scenario, but if you just lace returns in, the possibility goes away in full while simplifying the control flow considerations.

IE.

try:
  # Need redirects to deal with the variance of file servers and urls
  response = self.session.head(url, allow_redirects=True)
except RequestError:
  # should this be debug logged, or does something further down the chain log  it?
  return None
except SSLError as e:
  return SSLCertificateError("SRC_URI", url, str(e), pkg=pkg)
  
content_type = response.headers.get("Content-Type")
# Filtering out text/html matches is useful due to possible false matches with authentication
if (
  response.ok
  and content_type is not None
  and not content_type.startswith("text/html")
):
  return DetachedSignatureAvailable(filename, url, pkg=pkg)
return None

That's just an observation of a possible improvement.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, one tweak here simplifies things:

# Filtering out text/html matches is useful due to possible false matches with authentication
if (
  response.ok
  and not response.headers.get("Content-Type", "").startswith("text/html")
):

You can skip the intermediate content_type

@parona-source
Copy link
Contributor Author

I couldn't fully follow precedent with the network tests. The check deals with multiple network requests in one go so just a mocking of the returnvalue wasn't enough.

I don't know that code in question, but that sounds like something our test utilities should be enhanced to support. Mind cutting a ticket laying out what you think it should be? IE, what would've allowed you to use it rather than having to sidestep it?

I meant that with other network tests are simpler with having only one request triggered. So instead of simply setting requests = ... etc in responses.py, I had to have a function where I kept the implementation details for Session in mind. (Which is where @contextmanager and yield come from).

Example:
https://github.com/pkgcore/pkgcheck/blob/master/testdata/repos/network/MetadataUrlCheck/HttpsUrlAvailable/responses.py

Session:
https://github.com/pkgcore/pkgcheck/blob/master/src/pkgcheck/addons/net.py#L36

I don't see an issue with it as is, it currently means there is some ready made boilerplate for the next time its needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants